package Tabs;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import MainMethods.FileWr;
import MainMethods.HoverImage;
import MainMethods.Screenshot;


public class Software {
	HoverImage hover = new HoverImage();
	Screenshot scsh = new Screenshot();
	
	public void softwareTest(WebDriver driver, FileWr file, String screenDir) {
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		// Select software tab
		driver.findElement(By.id("software_tab")).click();
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		if (driver.getCurrentUrl().equals(
				"http://staging.membersarea.jomediainc.com/#software")) {
			System.out.println("SOFTWARE opened");
			file.writeFile("Select software tab - PASSED");
		} else {
			System.out.println("SOFTWARE opened failed");
			file.writeFile("Select software tab - FAILED");
		}
		
		// Click on the arrow button over any app
		hover.playHover(driver);
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		scsh.makeScreen("soft (Click on the arrow button over any app)", screenDir);
		try {
			Robot robot = new Robot();
			robot.keyPress(KeyEvent.VK_ESCAPE);
		} catch (AWTException e) {
			e.printStackTrace();
		}
		file.writeFile("Click on the arrow button over any app - PASSED");
		System.out.println("The apps is downloaded");
		// Go back to software tab
		driver.findElement(By.id("software_tab")).click();
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		if (driver.getCurrentUrl().equals(
				"http://staging.membersarea.jomediainc.com/#software")) {
			System.out.println("SOFTWARE opened");
			file.writeFile("Go back to software tab - PASSED");
		} else {
			System.out.println("SOFTWARE opened failed");
			file.writeFile("Go back to software tab - FAILED");
		}
		// Click on "Add to collection" (plus button)
		hover.addToCollection(driver);
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		if (driver.findElement(By.className("message")).isEnabled()) {
			System.out.println("Software added to collection");
			file.writeFile("Click on 'Add to collection' (plus button) - PASSED");
			driver.findElement(By.xpath("//*[@id=\"feedback\"]/div[3]")).click();
		} else {
			file.writeFile("Click on 'Add to collection' (plus button) - FAILED");
		}

		// Click on "download now" (plus button)
		hover.addToCollectionMus(driver);
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		scsh.makeScreen("soft (Click on download now (plus button))", screenDir);
		try {
			Robot robot = new Robot();
			robot.keyPress(KeyEvent.VK_ESCAPE);
		} catch (AWTException e) {
			e.printStackTrace();
		}
		if (driver.findElement(
				By.xpath("//*[@id=\"title_download_container\"]/a"))
				.isEnabled()) {
			System.out
					.println("Software downloaded by Click on 'download now' (plus button)");
			file.writeFile("Click on 'download now' (plus button) - PASSED");
		}
		// Download software from More like section
		hover.moreLike(driver);
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		scsh.makeScreen("soft (Download software from More like section)", screenDir);
		try {
			Robot robot = new Robot();
			robot.keyPress(KeyEvent.VK_ESCAPE);
		} catch (AWTException e) {
			e.printStackTrace();
		}
		System.out
				.println("Software downloaded by click on the arrow button over any app in 'More like' section");
		file.writeFile("Download software from More like section - PASSED");
		// enter collection and download soft
		driver.findElement(
				By.xpath("//*[@id=\"sidenav-your-stuff\"]/ul/li[1]/a/span[1]"))
				.click();
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		if (driver.getCurrentUrl().equals(
				"http://staging.membersarea.jomediainc.com/#member/collection")) {
			System.out.println("Open Collection - PASSED");
			file.writeFile("Open Collection - PASSED");
		} else {
			System.out.println("Open Collection - FAILED");
			file.writeFile("Open Collection - FAILED");
		}
		// download from collection
		hover.fromColl(driver);
		try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		scsh.makeScreen("soft (download from collection)", screenDir);
		try {
			Robot robot = new Robot();
			robot.keyPress(KeyEvent.VK_ESCAPE);
		} catch (AWTException e) {
			e.printStackTrace();
		}
		if (driver.findElement(
				By.xpath("//*[@id=\"title_download_container\"]/a"))
				.isEnabled()) {
			System.out.println("download from collection");
			file.writeFile("download from collection - PASSED");
		} else {
			file.writeFile("download from collection - FAILED");
		}
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		// Click on the arrow button over any app from because section
		driver.findElement(By.id("software_tab")).click();
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		hover.becauseSect(driver);
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		scsh.makeScreen("soft (because section)", screenDir);
		try {
			Robot robot = new Robot();
			robot.keyPress(KeyEvent.VK_ESCAPE);
		} catch (AWTException e) {
			e.printStackTrace();
		}
		if (driver.findElement(
				By.xpath("//*[@id=\"title_download_container\"]/a"))
				.isEnabled()) {
			System.out
					.println("Click on the arrow button over any app from because section");
			file.writeFile("Click on the arrow button over any app from because section - PASSED");
		} else {
			file.writeFile("Click on the arrow button over any app from because section - FAILED");
		}
	}

}
